package com.opensso.client.ctrl;


import com.opensso.core.entity.BeanRet;
import com.opensso.client.service.VerifySV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/verify")
@Slf4j
@Api(value = "验证控制器", description = "验证控制器")
public class VerifyCtrl {

    //验证token的service
    @Autowired
    private VerifySV verifySV;

    /**
     * 验证token
     *
     * @param Token
     * @param ApiKey 生成token的秘钥
     * @return
     */
    @ApiOperation(value = "验证token", notes = "验证token")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Token", value = "Token", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "ApiKey", value = "ApiKey", dataType = "String", paramType = "query")
    })
    @PostMapping("/verifyToken")
    @ResponseBody
    public BeanRet verifyToken(String Token, String ApiKey) {
        boolean isVerify = verifySV.verifyToken(Token, ApiKey);
        if (isVerify) {
            return BeanRet.create(true, "");
        } else {
            return BeanRet.create(false, "");
        }
    }
}
